<template>
  <div>
    <nav-bar title="加班管理"></nav-bar>
    <div class="maxinBox">
      <div v-if="user && user.userType === '01'" class="backgroundfff hotCardManage">
        <van-tabs type="card" v-model="active" @change="getOvertimeDataList">
          <van-tab title="待审批">
            <div v-if="dataList.length === 0" class="noData">
              <img src="../../../assets/images/noData.png" alt="">
              <p class="center">暂无数据</p>
            </div>
            <card v-else v-for="(item, index) in dataList" :key="index" :itemData="item" @click.native="getDetails(item)"></card>
          </van-tab>
          <van-tab title="已审批">
            <div v-if="dataList.length === 0" class="noData">
              <img src="../../../assets/images/noData.png" alt="">
              <p class="center">暂无数据</p>
            </div>
            <card v-else v-for="(item, index) in dataList" :key="index" :itemData="item" @click.native="getDetails(item)"></card>
          </van-tab>
        </van-tabs>
      </div>
      <div class="backgroundfff hotCardManage" v-else>
        <div v-if="dataList.length === 0" class="noData">
          <img src="../../../assets/images/noData.png" alt="">
          <p class="center">暂无数据</p>
        </div>
        <card v-else v-for="(item, index) in dataList" :key="index" :itemData="item" @click.native="getDetails(item)"></card>
        <div class="marginTop5 backgroundfff">
          <div style="width: 80%;margin: 0 auto;padding: 0.3125rem 0;position: fixed;bottom: 0;left: 10%;">
            <van-button round block type="info" @click="onAddOvertimePay">
              发起申请
            </van-button>
          </div>
        </div>
      </div>
    </div>

  </div>
</template>

<script>
  import Card from './components/card.vue'
  import overtimePayManage from '../../../api/workAPI/overtimePayManage.js'
  export default {
    components: {
      Card
    },
    data() {
      return {
        dataList: [],
        active: 0,
        user: {
          userStatus: '',
          userType: '',
        }
      }
    },
    methods: {
      getOvertimeList() {
        overtimePayManage.getWorkOvertimeList().then(res => {
          this.dataList = res
        })
      },
      getOvertimeDataList() {
        overtimePayManage.getWorkOvertimeDataList(this.active + 1).then(res => {
          this.dataList = res
        })
      },
      getDetails(data) {
        localStorage.setItem('overTimeData', JSON.stringify(data))
        this.$router.push({
          name: 'OvertimePayDetails'
        })
      },
      onAddOvertimePay() {
        this.$router.push({
          name: 'AddOvertimePay'
        })
      }
    },
    mounted() {
      this.user.userStatus = localStorage.getItem('userStatus')
      this.user.userType = localStorage.getItem('userType')
      if (this.user && this.user.userType === '01') {
        this.getOvertimeDataList()
      } else {
        this.getOvertimeList()
      }
    }
  }
</script>
<style scoped lang="scss">
  .noData{
    padding: 20% 0;
    width: 100%;
    text-align: center;
    img {
      width: 60%;
    }
  }
  .hotCardManage{
    .hotCardData{
      padding: 0.9375rem;
      font-size: 0.875rem;
      border-bottom: 0.0625rem solid #E5E5E5;
    }
  }
  /deep/ .van-tabs__wrap{
    .van-tabs__nav--card{
      border: inherit;
      margin: inherit;
      .van-tab.van-tab--active{
        background-color: #fff;
        color: #1577FF;
      }
      .van-tab{
        border: inherit;
        color: #999;
        background-color: #EBEBEB;;
      }
    }
  }
</style>
